import axios from 'axios';
import React from 'react'
import { useLocation } from 'react-router-dom'


const Index: React.FC = () =>  {
  const location = useLocation();
  const price = location.state.price as number
  const title = '花呗还款'
  const id = new Date().getTime();

  const handlePay = async () => {
    const resp = await axios.post('/api/pay', { id, title, price });
    window.location.href = resp.data.data
  }
  return (
    <div>
      <div>
        <h2>{id}</h2>
        <h2>{price}</h2>
        <h2>{title}</h2>
      </div>
      <button onClick={handlePay}>立即还款</button>
    </div>
  )
}

export default Index
